package com.fancymusic.controller;

import com.fancymusic.entity.BaseResult;
import com.fancymusic.entity.Manager;
import com.fancymusic.service.IManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ManagerController {

    @Autowired
    IManagerService iManagerService;

    @RequestMapping("login")
    public BaseResult<Manager> login(@RequestBody Manager manager){
        BaseResult<Manager> baseResult = new BaseResult<>();


        System.out.println("ManagerController===login==="+manager);
        Manager managerByName = iManagerService.getManagerByName(manager);

        if (managerByName==null){
            baseResult.setMessage("用户不存在");
            baseResult.setState(false);
            return baseResult;
        }

        if (managerByName!=null && !managerByName.getPassword().equals(manager.getPassword())){
            baseResult.setMessage("用户密码错误");
            baseResult.setState(false);
            return baseResult;
        }
        baseResult.setMessage("登录成功，点击登录");
        baseResult.setState(true);
        System.out.println("ManagerController===managerByName==="+managerByName);
        return baseResult;
    }
}
